/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entity.MMapHospitalDoctor;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Munliga
 */
@Stateless
public class MMapHospitalDoctorFacade extends AbstractFacade<MMapHospitalDoctor> {
    @PersistenceContext(unitName = "MedicalHub-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public MMapHospitalDoctorFacade() {
        super(MMapHospitalDoctor.class);
    }

    //Create Query
    public List<MMapHospitalDoctor> findByDoctorId(String ddlDoctorId) {
        try {
            String strQuery = "SELECT m FROM MMapHospitalDoctor m ";
            String strWhere = " Where 1=1 ";
            strWhere += (!ddlDoctorId.isEmpty()) ? " AND m.mDoctor.id = " + Integer.parseInt(ddlDoctorId) + " " : " ";
            strQuery += strWhere;
            return em.createQuery(strQuery).getResultList();
        } catch (Exception e) {
            return null;
        }
    }

}
